/**
 * @Author: Bobby
 * @Date: 2022-01-07 20:41:02
 * @LastEditTime: 2022-03-03 15:32:31
 * @LastEditors: Bobby
 * @Description:
 * @FilePath: \wms-v2\src\common\project\bootstrap\mainApp.js
 * @CIMC-V2
 */

import vuEPG, { useVuEPG } from "./vueEpg/index";

import '@/assets/tailwindcss.css'
import axios from 'axios'

import App from '@project/App.vue'
import { createApp } from 'vue'
import { setupVui } from '@/vui'
import { setupRouter } from '@commonProject/router'
import { setupStore } from '@commonProject/store'
import store from '@commonProject/store'

import { loadServerConfig } from '@project/config'
// import WebSocketConnect from '@commonProject/socket/WebSocketConnect'
import { translateTitle } from '@/utils/i18n'
import '@/utils/pda/CIMC/start.js'
window.Translate = translateTitle
//浏览器指纹生成
import canvasFP from '@/utils/canvasFP.js'

store.dispatch('tmp/setFingerprint', `${canvasFP({ uid: store.getters['user/uid'] || '' }).hash}`)

const app = createApp(App)
const epg = useVuEPG();
epg.setConfig({
  // debug: true,
});

app.use(vuEPG);
if (process.env.VUE_APP_ENV === 'development') {
  app.config.performance = true
}
console.log('测试加载-main')
// setup
function setupApp() {
  setupVui(app)
  setupStore(app)
  setupRouter(app, store)
    .isReady()
    .then(() => {
      app.mount('#app')
      console.log('测试加载-mount')
      // console.log('store', store.getters['fileConfig/data']['common']['websocketUrl'])
    })
}

// 依赖v2基座时引用
export function appStart() {
  if (loadServerConfig) {
    axios
      .get(`serverConfig.json?time=${new Date().getTime()}`)
      .then((result) => {
        // set data
        store.dispatch('fileConfig/setData', result.data)
        // setup app
        setupApp()
        //websocket 启动
        // WebSocketConnect()
      })
      .catch((error) => {
        console.log(error)
      })
  } else {
    // setup app
    setupApp()
  }
}
